﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.ProductionWorking;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MediatR;

namespace MangoMes.Write.API.Applications.ProductionWrite
{
    public class ProductionUpdHandler : IRequestHandler<ProductionUpdCommand, ResultsDTO>
    {
        private readonly IBateRepository<ProductionWork> _productionRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="productionRepository"></param>
        public ProductionUpdHandler(IBateRepository<ProductionWork> productionRepository)
        {
            _productionRepository = productionRepository;
        }
        /// <summary>
        /// 审批状态
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ResultsDTO> Handle(ProductionUpdCommand request, CancellationToken cancellationToken)
        {
            var list = new ResultsDTO() { Code = 0 };

            //连接数据库
            DapperHelper dapper = new DapperHelper();
            var conn = dapper.MangoMesWrite;

            //实体
            var sellStock = new ProductionWork();
            var str = "update productionwork set ProductionStart='" + request.ProductionStart + "' where ProductionWorkId='" + request.ProductionWorkId + "'";
            var result = _productionRepository.Add(str, sellStock, conn);
            if (result != null)
            {
                list.Code = 1;
                list.Message = "修改成功";
            }
            return list;
        }
    }
}
